﻿using System;
using Microsoft.Xna.Framework;

namespace Firefly.Framework.Input
{
    public class MouseScrollWheelMap : InputMap, IPositionMapEx<int, MouseManager, MouseScrollWheelMapEventArgs>
    {
        public MouseScrollWheelMap()
            : this(string.Empty)
        {
        }

        public MouseScrollWheelMap(string action)
            : base()
        {
            InputMapType = InputMapType.MouseScrollWheelMap;
            Action = action;
            InputService.Instance.RegisterInputMap(this);
        }

        #region IPositionMap Members

        public int CurrentPosition
        {
            get { return Manager.CurrentScrollWheelPosition; }
        }
        public int PreviousPosition
        {
            get { return Manager.PreviousScrollWheelPosition; }
        }
        public int PositionDelta
        {
            get { return Manager.ScrollWheelDelta; }
        }

        #endregion

        #region IPositionMapEx Members

        public event EventHandler<MouseScrollWheelMapEventArgs> PositionChanged;

        private void NotifyPositionChanged()
        {
            EventHandler<MouseScrollWheelMapEventArgs> handler = PositionChanged;

            if (handler != null)
            {
                handler(this, new MouseScrollWheelMapEventArgs(this));
            }
        }

        #endregion

        #region IHasInputManager Members

        public MouseManager Manager { get; set; }

        #endregion

        #region IUpdateable Members

        public override void Update(GameTime gameTime)
        {
            if (Enabled)
            {
                if (CurrentPosition != PreviousPosition)
                {
                    NotifyPositionChanged();
                }
            }
        }

        #endregion
    }
}
